import { createI18n } from 'vue-i18n'
import type { App } from 'vue'

// 导入语言包
import primevueZhCN from '@/locales/primevue-langs/zh-CN.json'
import primevueEnUS from '@/locales/primevue-langs/en.json'
import zhCN from '@/locales/langs/zh-CN.json'
import enUS from '@/locales/langs/en.json'
import { getBrowserLang } from '@/utils/locales'

// 定义支持的语言类型
export type Locale = 'zh-CN' | 'en-US'

// 导出语言包配置
export const LOCALES: Record<Locale, any> = {
  'zh-CN': {
    ...primevueZhCN['zh-CN'],
    ...zhCN,
  },
  'en-US': {
    ...primevueEnUS['en'],
    ...enUS,
  },
}

//console.log(getBrowserLang())

// 创建 i18n 实例
export const i18n = createI18n({
  legacy: false,
  locale: getBrowserLang(),
  fallbackLocale: 'zh-CN',
  messages: LOCALES,
  globalInjection: true,
})

export function setupI18n(app: App) {
  app.use(i18n)
}
